﻿
@{
    ViewBag.Title = "我的日程-指效";
}
<link href="/Static/styles/bootstrap.min.css" rel="stylesheet" />
<link type="text/css" rel="stylesheet" href="/Static/js/layui/css/layui.css" />
<link href="/Static/js/layer/need/layer.css" rel="stylesheet" />
<link href="/Static/js/calendar/zui.calendar.min.css" rel="stylesheet" />
<script src="/Static/js/jquery/jquery-1.11.1.min.js"></script>
<script src="/Static/js/layui/layui.js"></script>
<script src="/Static/js/zui/zui.min.js"></script>
<script src="/Static/js/calendar/zui.calendar.min.js"></script>
<script src="/Static/js/layer/layer.js"></script>
<script src="/Static/js/layer/layer.tools.js"></script>
@Html.Raw(ViewBag.SysAdminMainNavbar)
<input type="hidden" name="currentMid" id="currentMid" value="@ViewBag.CurrentMid" />
<input type="hidden" id="secondMenuId" name="secondMenuId" value="@ViewBag.SecondMenuId" />
<style>
    .top-navbar-index {
        position: inherit;
        background-color: white;
        width: 100%;
        margin-bottom: 0;
    }

    .active {
        float: left;
    }

    .layui-icon {
        font-size: 18px;
        height: 20px;
        width: 20px;
    }

    .btn {
        padding: 2px 12px !important;
    }
</style>
<nav id='menu'>
    <ul class='nav'>
        <li class='active'>
            <a href='javascript:;' onclick="jumpMyCalendar()">日历</a>
        </li>
        <li class='active'>
            <a href='javascript:;' onclick="jumpMyAgendaAll()">所有</a>
        </li>
        <li class='active'>
            <a href='javascript:;' onclick="jumpAssignOther();">指派他人</a>
        </li>
        <li class='active'>
            <a href='javascript:;' onclick="jumpAssignMy();">指派给我</a>
        </li>
        <li class='active'>
            <a href='javascript:;' onclick="jumpUnfinished();">未完成</a>
        </li>
        <li class='active'>
            <a href='javascript:;' onclick="jumpUndetermined();">待定</a>
        </li>
    </ul>
</nav>
<div class='with-menu'>
    <div id="calendar" class="calendar"></div>
</div>
<script type="text/javascript">
    $(function () {
        $('#calendar').calendar();
        bindCalendar();
    });

    var calendar = $('#calendar').data('zui.calendar');
    //单击单元格
    $('#calendar').calendar().on("clickCell.zui.calendar", function (event) {
        add(event);
    });
    //单击一个事件
    $('#calendar').calendar().on("clickEvent.zui.calendar", function (event) {
        win.open("/My_Agenda/EventAgenda?Id=" + event.event.id, 1000, 500, event.event.title + "信息");
    });


    function bindCalendar() {
        $.post("/My_Agenda/GetAgendaList", { mid: $("#currentMid").val(), secondMenuId: $("#secondMenuId").val() }, function (data) {
            win.hideLoading();
            if (data.Code == 200) {
                /* 增加事件 */
                var calendar = $('#calendar').data('zui.calendar');

                $.each(data.Data, function (i, item) {

                    var newEvent = { id: item.Id, title: item.AName, desc: item.ADesc, start: JsonToTime(item.ADate, "yyyy-MM-dd") + " " + item.AStartmmhh + ":00", end: JsonToTime(item.ADate, "yyyy-MM-dd") + " " + item.AEndmmhh + ":00" };
                    calendar.addEvents(newEvent);
                    calendar.display();
                });

            } else {
                win.alert("获取数据失败");
            }
        });
    }

    function add(event) {
        var d = new Date(event.date);
        var year = d.getFullYear();
        var month = d.getMonth() + 1;
        if (month < 10) {
            month = "0" + month;
        }
        var date = d.getDate()
        if (date < 10) {
            date = "0" + date;
        }
        d = year + '-' + month + '-' + date;
        win.open("/My_Agenda/My_AgendaListAdd?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val() + "&AgendDate=" + d, 1000, 530, "待办新增");
    }

    function jumpMyCalendar() {
        window.location.href = "/PersonalSpace/MyCalendar?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }

    function jumpMyAgendaAll() {
        window.location.href = "/My_Agenda/Index?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }

    function jumpAssignOther() {
        window.location.href = "/My_Agenda/AssignedOtherList?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }
    function jumpAssignMy() {
        window.location.href = "/My_Agenda/AssignedMyList?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }
    function jumpUnfinished() {
        window.location.href = "/My_Agenda/UnfinishedList?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }
    function jumpUndetermined() {
        window.location.href = "/My_Agenda/IsUndeterminedList?mid=" + $("#currentMid").val() + "&secondMenuId=" + $("#secondMenuId").val();
    }

    /**
 * 格式化时间
 */
    function JsonToTime(date, fmt) {
        var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
        var Year = da.getFullYear();
        var Month = da.getMonth() + 1;
        var Day = da.getDate();
        var Hours = da.getHours();
        var Minutes = da.getMinutes();
        var Seconds = da.getSeconds();
        if (Month < 10) {
            Month = "0" + Month;
        }
        if (Day < 10) {
            Day = "0" + Day;
        }
        if (Hours < 10) {
            Hours = "0" + Hours;
        }
        if (Minutes < 10) {
            Minutes = "0" + Minutes;
        }
        if (Seconds < 10) {
            Seconds = "0" + Seconds;
        }
        switch (fmt) {
            case "yyyy":
                return Year;
                break;
            case "yyyy-MM":
                return Year + "-" + Month;
                break;
            case "yyyy-MM-dd":
                return Year + "-" + Month + "-" + Day;
                break;
            case "yyyy-MM-dd HH":
                return Year + "-" + Month + "-" + Day + " " + Hours;
                break;
            case "yyyy-MM-dd HH:mm":
                return Year + "-" + Month + "-" + Day + " " + Hours + ":" + Minutes;
                break;
            case "MM-dd HH:mm:ss":
                return Month + "-" + Day + " " + Hours + ":" + Minutes + ":" + Seconds;
                break;
            case "dd HH:mm:ss":
                return Day + "号 " + Hours + ":" + Minutes + ":" + Seconds;
                break;
            case "HH:mm:ss":
                return Hours + ":" + Minutes + ":" + Seconds;
                break;
            case "mm:ss":
                return Minutes + ":" + Seconds;
                break;
            case "HH:mm":
                return Hours + ":" + Minutes;
                break;
            case "MM-dd HH:mm":
                return Month + "-" + Day + " " + Hours + ":" + Minutes;
                break;
            default:
                return Year + "-" + Month + "-" + Day + " " + Hours + ":" + Minutes + ":" + Seconds;
                break;
        }
    }

    function agendaPoint(id, mid, secondMid) {
        win.open("/My_Agenda/Point?id=" + id + "&mid=" + mid + "&secondMenuId=" + secondMid, 800, 509, "待办指派");
    }
</script>
